function localData(user) {
    let localdata = {}
    localdata.getbyId = function (id) {
        let data_list = JSON.parse(localStorage.getItem(user))
        data_list === null ? data_list = [] : data_list
        data_list instanceof Array ? data_list : data_list = Object.keys(data_list)
        return data_list.find(value => {
            return value.id == id
        });
    }
    localdata.getdata = function () {
        let data_list = JSON.parse(localStorage.getItem(user))
        data_list === null ? data_list = [] : data_list
        data_list instanceof Array ? data_list : data_list = Object.keys(data_list)
        return data_list
    }
    localdata.setData = function (data) {
        let data_list = JSON.parse(localStorage.getItem(user))
        data_list === null ? data_list = [] : data_list
        data_list instanceof Array ? data_list : data_list = Object.keys(data_list)
        if (data_list.length != 0) {
            let getdata = data_list.find(value => {
                return value.id == data.id
            });
            if (getdata === undefined) {
                console.log("nun", data.num);
                data.num ? 0 : data.num = 1
                data_list.push(data)
            } else {
                getdata.num ? ++getdata.num : getdata.num = 1
            }
        } else {
            data.num ? 0 : data.num = 1
            data_list.push(data)
        }
        localStorage.setItem(user, JSON.stringify(data_list))
    }
    localdata.updata = function (id, data) {
        let data_list = JSON.parse(localStorage.getItem(user))
        data_list === null ? data_list = [] : data_list
        data_list instanceof Array ? data_list : data_list = Object.keys(data_list)
        for (let i = 0; i < data_list.length; i++) {
            if (data_list[i].id == id) {
                if (data.num <= 0)
                    localdata.delectdata(id)
                else {
                    data_list[i].checked?0:data_list[i].checked=false
                    data_list[i]={...data_list[i],...data}
                    localStorage.setItem(user, JSON.stringify(data_list))
                    return 1
                }
            }
        }
    }
    localdata.delectdata = function (id) {
        let data_list = JSON.parse(localStorage.getItem(user))
        data_list === null ? data_list = [] : data_list
        data_list instanceof Array ? data_list : data_list = Object.keys(data_list)
        for (let i = 0; i < data_list.length; i++) {
            if (data_list[i].id == id) {
                data_list.splice(i, 1)
                break;
            }
        }
        localStorage.setItem(user, JSON.stringify(data_list))
    }
    return localdata
}